local Sheild = class("Sheild")

local ELEMENT_ATTENUATE = 0.75

function Sheild:ctor(id, baseId, value, element)
    self._id = id
    self._baseId = baseId
    self._value = value
    self._element = element
    self._initValue = value
end

function Sheild:setEntity(entity)
    self._entity = entity
end

function Sheild:getId()
    return self._id
end

function Sheild:getBaseId()
    return self._baseId
end

function Sheild:getValue()
    return self._value
end

function Sheild:beAttack(hurt, element)
    if self._element == element then
        self._value = self._value - hurt * ELEMENT_ATTENUATE
    else
        self._value = self._value - hurt
    end
    self._value = math.floor(self._value)
    if self._value < 0 then
        local retValue = self._value
        self._value = 0
        return math.abs(retValue)
    else
        return 0
    end
end

function Sheild:isBroken()
    return self._value <= 0
end

function Sheild:changeValue(value)
    if self._value >= value then
        return
    end
    self._value = value
end

function Sheild:remove(battleReport)
    battleReport:removeSheild(self, self._entity)
    self._condition = nil
end

function Sheild:setCondition(condition)
    self._condition = condition
end

return Sheild
